{#include main}
{#style}
.ddl-script {
    padding: 5px;
}
.hidden {
    display: none;
}
th .badge {
    font-size: 100%;
}
a.script-heading {
    display: block;
    float:left;
    width: 90%;
    text-decoration: none;
}
{/style}
{#title}Persistence Units{/title}
{#body}

{#if info:persistence.persistenceUnits.isEmpty}
<p>No persistence units found.</p>
{#else}
{#for pu in info:persistence.persistenceUnits}
<table class="table table-striped">
    <thead class="thead-dark">
    <tr>
        <th scope="col">Persistence Unit <i class="badge badge-info">{pu.name}</i></th>
    </tr>
    </thead>
    <thead class="thead-light">
    <tr>
        <th scope="col">
            <a href="#" onclick="toggleExpanded(this, 'td-create-script-{pu_count}'); return false;" class="script-heading">
                <span class="fa fa-chevron-right icon"></span>
                <span>Create Script</span>
            </a>
            <a href="#" onclick="copyToClipboard('create-script-{pu_count}'); return false;" class="float-right badge">
                <span class="fa fa-clipboard"></span> Copy</a>
        </th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td id="td-create-script-{pu_count}" class="hidden">
            <pre id="create-script-{pu_count}" class="ddl-script">{pu.createDDL}</pre>
        </td>
    </tr>
    <thead class="thead-light">
    <tr>
        <th scope="col">
            <a href="#" onclick="toggleExpanded(this, 'td-drop-script-{pu_count}'); return false;" class="script-heading">
                <span class="fa fa-chevron-right icon"></span>
                <span>Drop Script</span>
            </a>
            <a href="#" onclick="copyToClipboard('drop-script-{pu_count}'); return false;" class="float-right badge">
                <span class="fa fa-clipboard"></span> Copy</a>
        </th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td id="td-drop-script-{pu_count}" class="hidden">
            <pre id="drop-script-{pu_count}" class="ddl-script">{pu.dropDDL}</pre>
        </td>
    </tr>
    </tbody>
</table>
{/for}
{/if}

<script>
<!--
function copyToClipboard(elementId) {
    var text = document.getElementById(elementId).textContent;
    var listener = function(ev) {
	    ev.clipboardData.setData("text/plain", text);
	    ev.preventDefault();
    };
    document.addEventListener("copy", listener);
    document.execCommand("copy");
    document.removeEventListener("copy", listener);
}

function toggleExpanded(link, expandableElementId) {
    var expandedClass = 'fa-chevron-down';
    var collapsedClass = 'fa-chevron-right';

    var icon = link.getElementsByClassName('icon')[0];

    var element = document.getElementById(expandableElementId);
    if (element.classList.contains('hidden')) {
        element.classList.remove('hidden');
        icon.classList.remove(collapsedClass);
        icon.classList.add(expandedClass);
    } else {
        element.classList.add('hidden');
        icon.classList.add(collapsedClass);
        icon.classList.remove(expandedClass);
    }
}
//-->

</script>

{/body}
{/include}
